#include "game.h"

int lastx, lasty;

Game::~Game() {
    delete board;
    delete player[0];
    delete player[1];
}

Game::Game(Board* board) : board(board) {
    player[0] = nullptr;
    player[1] = nullptr;
};

int Game::getStatus(int x, int y) {
    return board->getStatus(x, y);
}
void Game::setStatus(int x, int y, int _status) {
    now ^= 1;
    board->setStatus(x, y, _status);
    lastx = x;
    lasty = y;
    if (_status != 0) {
        history.push_back(std::make_pair(x, y));
    }
}

int Game::rule(int x, int y) {
    return this->board->rule(x, y);
}

Player* Game::getPlayer() {
    return player[now];
}

void Game::setPlayer(int num, int type, int order) {
    switch (type) {
        case 0:
            player[num] = new Human((num == 0) ? 1 : -1, board);  // TODO：默认人类玩家0为黑色，人类玩家1为白色
            break;
        case 1:
            player[num] = new Ai((order == 0) ? -1 : 1, difficulty, board);  // TODO：默认AI玩家1颜色为白色
            break;
        default:
            break;
    }
}
void Game::init() {
    delete board;
    history.clear();
    board = new Board;
}
void Game::setDifficulty(int i) {
    difficulty = i;
}
int Game::getDifficulty() {
    return difficulty;
}
